<?php
class Mcabins extends CI_Model{
		protected $_table = "cabins";
		protected $dbcheckrate;
		protected $_cruises = "tbl_sheep";
		protected $_agencycs = "tbl_agecruise";
		public function __construct(){
			parent::__construct();
			$this->load->database();
		}
		public function getdata($id){
			$this->db->where("id",$id);
			$data=$this->db->get($this->_table)->row_array();
			if(count($data)>0)
				return $data;
			return array(
				"id"=>0,
				"name"=>"",
				"avatar"=>"nofile",
				"width"=>0,
				"aircon"=>0,
				"standingshower"=>0,
				"balcony"=>0,
				"tivi"=>0,
				"terrace"=>0,
				"jaccuzi"=>0,
				"inhousebuffer"=>0,
				"customisableprograme"=>0,
				"dinningpreference"=>0,
				"details"=>"",
				"cruisename"=>""
			);
		}
		public function listall(){
			return $this->db->get($this->_table)->result_array();
		}
		public function listcruises($userid){
			$this->db->select("sheep_id,sheep_name,sheep_status,agency_id,agency_name,cruises_id");
			$this->db->join($this->_cruises,"tbl_sheep.sheep_id = tbl_agecruise.cruises_id");
			$this->db->where($this->_cruises.".sheep_status",1);
			$this->db->where($this->_agencycs.".agency_id",$userid);
			return $this->db->get($this->_agencycs)->result_array();
		}
		public function listallbySheepid($id){
			$query=$this->db->query("select * from cabins where cruisename=".$id);
			return $query->result_array();
		}
		
		public function add($data){
        	$this->db->insert($this->_table,$data);
		}
		public function update($data,$id){
			$this->db->where("id",$id);
			$this->db->update($this->_table,$data);
		}
		public function del($id){
			$this->db->where("id",$id);
			$this->db->delete($this->_table);
		}
		public function getAllByShipid($shipid){
			$this->db->where("cruisename",$shipid);
			return $this->db->get($this->_table)->result_array();
		}
	}